<template>
  <div id="centerLeft1">
    <div class="bg-color-black">
      <div class="d-flex pt-2 pl-2">
        <span>
          <icon name="chart-bar" class="text-icon"></icon>
        </span>
        <div class="d-flex">
          <span class="fs-xl text mx-2">停靠时长分布占比</span>
          <dv-decoration-3 class="dv-dec-3" />
        </div>
      </div>
      <div class="bottom-data">
        <div id="chart_parking_time"></div>
      </div>
    </div>
  </div>
</template>

<script>
import echarts from "echarts";
import axios from "axios";
// import CenterLeft1Chart from '@/components/echart/centerLeft/centerLeft1Chart'
export default {
  data() {
    return {
      parkingTimeChart: undefined,
    };
  },
  components: {
    // CenterLeft1Chart
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      axios
        .get("https://dda-park.com/adminApi/dataView/parking/duration")
        .then((res) => {
          let chartData = [];
          for (let i = 0; i < res.data.length; i++) {
            chartData.push(res.data[i].y);
          }
          this.drawParkingTime(chartData);
        });
    },
    drawParkingTime(data) {
      let dom = document.getElementById("chart_parking_time");
      this.parkingTimeChart = echarts.init(dom);
      this.parkingTimeChart.setOption({
        tooltip: {
          trigger: "item",
          formatter: "停车时长分布占比:<br>{b}:{c} %",
        },
        legend: {
          data: ["已贯通"],
          textStyle: {
            color: "#B4B4B4",
          },
          top: "0%",
        },
        grid: {
          left: '8%',
          right: '4%s'
        },
        xAxis: {
          data: ["15分钟以内", "15-30分钟", "30分钟-2小时", "2小时以上"],
          axisLine: {
            lineStyle: {
              color: "#B4B4B4",
            },
          },
          axisTick: {
            show: false,
          },
        },
        yAxis: [
          {
            splitLine: { show: false },
            axisLine: {
              lineStyle: {
                color: "#B4B4B4",
              },
            },

            axisLabel: {
              formatter: "{value} ",
            },
          },
          {
            splitLine: { show: false },
            axisLine: {
              lineStyle: {
                color: "#B4B4B4",
              },
            },
            axisLabel: {
              formatter: "{value} ",
            },
          },
        ],
        series: [
          {
            name: "贯通率",
            type: "bar",
            smooth: true,
            showAllSymbol: true,
            symbol: "emptyCircle",
            // symbolSize: 4,
            // yAxisIndex: 1,
            itemStyle: {
              normal: {
                color: "#6495ED",
              },
            },
            data: data,
          },
        ],
      });
    },
  },
};
</script>

<style lang="scss" scoped>
#chart_parking_time {
  height: 380px;
  width: 480px;
}

$box-width: 100%;
$box-height: 410px;

#centerLeft1 {
  padding: 16px;
  height: $box-height;
  width: $box-width;
  border-radius: 10px;
  .bg-color-black {
    height: $box-height - 30px;
    border-radius: 10px;
  }
  .text {
    color: #c3cbde;
  }
  .dv-dec-3 {
    position: relative;
    width: 100px;
    height: 20px;
    top: -3px;
  }

  // .bottom-data {
  //   .item-box {
  //     & > div {
  //       padding-right: 5px;
  //     }
  //     font-size: 14px;
  //     float: right;
  //     position: relative;
  //     width: 50%;
  //     color: #d3d6dd;
  //     .dv-digital-flop {
  //       width: 120px;
  //       height: 30px;
  //     }
  //     // 金币
  //     .coin {
  //       position: relative;
  //       top: 6px;
  //       font-size: 20px;
  //       color: #ffc107;
  //     }
  //     .colorYellow {
  //       color: yellowgreen;
  //     }
  //     p {
  //       text-align: center;
  //     }
  //   }
  // }
}
</style>
